//
//  NoCardAppointmentViewViewController.m
//  FQPub
//
//  Created by rzhy on 2017/9/7.
//  Copyright © 2017年 rzhy. All rights reserved.
//

#import "NoCardAppointmentViewViewController.h"
#import "Config.h"
#import "Utils.h"
#import "AppointmentDetailController.h"

@interface NoCardAppointmentViewViewController ()
@property (weak, nonatomic) IBOutlet UIButton *button;
@property (weak, nonatomic) IBOutlet UITextField *nameTextField;
@property (weak, nonatomic) IBOutlet UITextField *numTextField;
@property (weak, nonatomic) IBOutlet UITextField *phoneTextField;

@end

@implementation NoCardAppointmentViewViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"无卡预约";
    self.button.layer.cornerRadius = 5.0f;
    self.button.layer.masksToBounds = YES;
}
// 无卡预约
- (IBAction)noCardAppointment {
    NSString *name = self.nameTextField.text;
    NSString *num = self.numTextField.text;
    NSString *phone = self.phoneTextField.text;
    if (!name || [name isEqualToString:@""]) {
        [self setAlertViewWithMessage:@"请输入姓名!"];
    } else if (![Utils matchingTelNumber: phone]) {
        [self setAlertViewWithMessage:@"请输入正确的手机号码!"];
    } else if (!num || [num isEqualToString:@""]) {
        [self setAlertViewWithMessage:@"请输入身份证号!"];
    } else if (num.length <= 0 || num.length != 18) {
        [self setAlertViewWithMessage:@"请输入正确身份证号!"];
    } else {
        AppointmentDetailController *appVc = [[AppointmentDetailController alloc] init];
        appVc.name = self.nameTextField.text;
        appVc.num = self.numTextField.text;
        appVc.phone = self.phoneTextField.text;
        [self.navigationController pushViewController: appVc animated: YES];
    }
}

#pragma mark - AlertView
- (void)setAlertViewWithMessage:(NSString *)message {
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示:" message:message preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *defaultAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
    [alertController addAction:defaultAction];
    [self presentViewController:alertController animated:YES completion:nil];
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [self.view endEditing: YES];
}
@end
